//
//  RequestEngine.m
//  HQJFacilitator
//
//  Created by mymac on 16/9/23.
//  Copyright © 2016年 Fujian first time iot technology investment co., LTD. All rights reserved.
//

#import "RequestEngine.h"

@implementation RequestEngine
+(void)HQJFacilitatorRequestDetailsUrl:(NSString *)urlStr complete:(void (^)(NSDictionary *dic))complete andError:(void(^)(NSError *error))errors ShowHUD:(BOOL)show
{
    if (show == YES) {
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
        [SVProgressHUD showWithStatus:@"加载中"];
    }
    [[AFHTTPSessionManager manager].operationQueue cancelAllOperations];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer.timeoutInterval = 30.f;
    
    manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
    
    NSLog(@"----%@",urlStr);

    [manager POST:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        if (complete)
        {
            complete(responseObject);
            [SVProgressHUD dismiss];

        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [SVProgressHUD dismiss];
        if (errors) {
            errors (error);
            
        }
        if ([error.userInfo[@"NSLocalizedDescription"]isEqualToString:@"似乎已断开与互联网的连接。"]) {
            [SVProgressHUD showErrorWithStatus:@"没网了"];
            
        }
        if([error.userInfo[@"NSLocalizedDescription"]isEqualToString:@"请求超时。"]) {
            [SVProgressHUD showErrorWithStatus:@"请求超时,请稍候重试"];
            
        }
        
        NSLog(@"Error:%@",error);
        
    }];
    
    
}

@end
